package com.online.servlet.user;

import com.online.pojo.Bill;
import com.online.pojo.User;
import com.online.pojo.menu;
import com.online.service.user.Impl.UserServiceImpl;
import com.online.service.user.Impl.billServiceImpl;
import com.online.service.user.Impl.merchantServiceImpl;
import com.online.service.user.UserService;
import com.online.service.user.billService;
import com.online.service.user.merchantService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ShowMenu extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        double price = Double.parseDouble(req.getParameter("price"));
        String shop_name = req.getParameter("shop_name");
        String type = req.getParameter("type");
        String user_name = req.getParameter("user_name");
        System.out.println(name + price + shop_name + type);
        List<menu> list = new ArrayList<menu>();
        merchantService merchantService = new merchantServiceImpl();

        try {
            merchantService.select(list, price, type,name,shop_name);
            req.setAttribute("m", list);
            req.setAttribute("user_name", user_name);
            UserService userService= new UserServiceImpl();
            billService billService=new billServiceImpl();
            User user= userService.login(user_name);
            List<Bill> billed=new  ArrayList<Bill>();
            billService.selectBilled(billed,user_name);
            req.setAttribute("billed",billed);
            List<Bill> bill=new  ArrayList<Bill>();
            billService.select(bill,user_name);
            req.setAttribute("bill",bill);
            req.setAttribute("user_name",user.getUser_name());
            req.setAttribute("account",user.getAccount());
            req.getRequestDispatcher("/jsp/orderpage.jsp").forward(req,resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req,resp);
}}
